package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.RecommendEntity;
import com.sgb.kjwl.view.ui.activity.manage.ShopInfoForCompanyTradesActivity;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopGoodsDetailActivity;
import com.sgb.kjwl.view.widget.RoundImageView;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class MaterialRecommendGoodsAdapter extends BaseRecycleAdapter<RecommendEntity> {

    private String type = "";
    private RelativeLayout root1;
    private RelativeLayout root2;
    private TextView companyView;
    private TextView titleView;
    private TextView tvPrice;
    private RoundImageView logoView;
    private LinearLayout intoLayout;

    public MaterialRecommendGoodsAdapter(Context context, List<RecommendEntity> datas) {
        super(context, R.layout.item_goods_detail_details_recommend, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final RecommendEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        root1 = holder.getItem().findViewById(R.id.root_layout1);
        root2 = holder.getItem().findViewById(R.id.root_layout2);
        companyView = holder.getItem().findViewById(R.id.company_view);
        TextView info = holder.getItem().findViewById(R.id.info);
        titleView = holder.getItem().findViewById(R.id.title_view);
        logoView = holder.getItem().findViewById(R.id.logo_view);
        intoLayout = holder.getItem().findViewById(R.id.into_layout);
        if (type.equals("material")) {
            companyView.setVisibility(View.VISIBLE);
            info.setVisibility(View.GONE);
        } else {
            companyView.setVisibility(View.GONE);
            info.setVisibility(View.GONE);
        }
        if (type.equals("recruit")) {
            root1.setVisibility(View.GONE);
            root2.setVisibility(View.VISIBLE);
        } else {

            root2.setVisibility(View.GONE);
            root1.setVisibility(View.VISIBLE);
            companyView.setVisibility(View.VISIBLE);
            tvPrice = holder.getItem().findViewById(R.id.price_view);
            if (entity.getNegotiable() == 1) {
                tvPrice.setText("面议");
            } else {
                tvPrice.setText("￥" + entity.getPrice() + entity.getPriceUnit());
            }

        }
        if (type.equals("material")) {
            companyView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (type.equals("material")) {
                        if (entity.getCompanyId().equals("0")) {
                            ShopGoodsDetailActivity.start(context, entity.getId(), "", entity.getSkuid());
                        } else {
                            ShopInfoForCompanyTradesActivity.startAct(context, entity.getCompanyId(), "", 0, 0);
                        }
                    }
                }
            });

            titleView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (type.equals("material")) {
                        ShopGoodsDetailActivity.start(context, entity.getId(), "", entity.getSkuid());
                    }
                }
            });

            tvPrice.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (type.equals("material")) {
                        ShopGoodsDetailActivity.start(context, entity.getId(), "", entity.getSkuid());
                    }
                }
            });

            logoView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (type.equals("material")) {
                        ShopGoodsDetailActivity.start(context, entity.getId(), "", entity.getSkuid());
                    }
                }
            });
        }
        intoLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShopInfoForCompanyTradesActivity.startAct(context, entity.getCompanyId(), "", 0, 0);
            }
        });
    }

    public void setType(String type) {
        this.type = type;
    }
}
